package com.antler.smt.admin.controller;

import com.antler.smt.admin.annotation.OperateCut;
import com.antler.smt.enums.ResultCodeEnum;
import com.antler.smt.request.admin.GetPurchaserListReq;
import com.antler.smt.response.admin.GetPurchaserListResp;
import com.antler.smt.response.base.Result;
import com.antler.smt.service.admin.PurchaserService;
import com.antler.smt.utils.LogUtil;
import com.antler.smt.validate.DataValidator;
import com.github.pagehelper.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 采购商Controller
 *
 * @author zhangyi
 * @date 2018/4/2 16:02
 */
@RestController
@RequestMapping("/purchaserBack")
@Api(description = "后台采购商控制接口")
public class PurchaserController {

    /**
     * 日志
     */
    private static Logger log = LogUtil.get();

    @Resource
    private PurchaserService purchaserService;


    /**
     * 采购商审核列表或者是待审核列表
     *
     * @param request 请求实体
     * @return
     */
    @PostMapping("/purchaserAuditList")
    @ApiOperation(value = "采购商审核列表或者是待审核列表", httpMethod = "POST")
    public Result<Page<GetPurchaserListResp>> purchaserAuditList(@RequestBody GetPurchaserListReq request){
        DataValidator.isNull(request,"采购商请求实体不能为空！");
        DataValidator.isBlank(String.valueOf(request.getAuditResult()),"审核结果不能空！");

        Result result = null;
            result = purchaserService.getPurchaserAuditResultList(request);
        return result;
    }

    /**
     * 采购商详情
     *
     * @return
     */
    @PostMapping("/purchaserInfo/{id}")
    @ApiOperation(value = "获取采购商详情", httpMethod = "POST")
    @OperateCut(content = "获取采购商详情")
    public Result<GetPurchaserListResp> purchaserInfo(@PathVariable Long id){
        DataValidator.isBlank(String.valueOf(id),"采购商id不能为空！");

        Result result = null;
            result = purchaserService.getPurchaserInfoById(id);
        return result;
    }
    /**
     * 采购商认证审核
     *
     * @return
     */
    @PostMapping("/purchaserAudit/{id}/{auditResult}")
    @ApiOperation(value = "采购商认证审核", httpMethod = "POST")
    @OperateCut(content = "采购商认证审核")
    public Result<ResultCodeEnum> purchaserAudit(@PathVariable Long id, @PathVariable Integer auditResult){
        DataValidator.isBlank(String.valueOf(id),"采购商id不能为空！");
        DataValidator.isBlank(String.valueOf(auditResult),"审核结果不能为空！");

        Result result = null;
            result = purchaserService.updatePurchaserAuditResult(id,auditResult);
        return result;
    }


}
